package TUILayer;
import java.util.Scanner;
import ControlLayer.*;

public class LoanUI
{
    private LoanCtr _loanCtr;

    public LoanUI()
    {
        _loanCtr = new LoanCtr();
    }
    
    public void start()
    {
        loanMenu();
    }
    
    public void loanMenu()
    {
       boolean exit = false;
       while(!exit)//that is: while exit is false
       {
          int choise = writeLoanMenu(); 
          if(choise == 1)
          {   //create loan
              createLoan();
          }
          else{
              if(choise == 2){
                    //remove loan
                    removeLoan();
              }  
              else{
                  if(choise == 3){
                      //list all loans
                      listAllLoans();
                  }  
                  else{
                      exit = true;
                    }//end else
                }//end else
            }//end else
            
       }//end while
    }
    public int writeLoanMenu()
    {      // makes an object keyboard to read input from the screen
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** Loan Menu ***");
            System.out.println(" (1) Create loan");
            System.out.println(" (2) Remove loan");
            System.out.println(" (3) List all loans");
            System.out.println(" (4) Return");
            System.out.print("\n Make your choice: ");
            
            int choise = keyboard.nextInt();

            return choise;
    }
    
    private long inputPersonID()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type person id: ");
        long id = keyboard.nextInt();
        return id;
    }
        
    private String inputTitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD title: " );
        String title = keyboard.nextLine();
        return title;
    }
    
    private long inputLendingID()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type lending id: ");
        long id = keyboard.nextInt();
        return id;
    }
    
    private String inputDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type date: " );
        String date = keyboard.nextLine();
        return date;
    }
    
    private String inputPeriod()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type period: " );
        String period = keyboard.nextLine();
        return period;
    }
    
    public void createLoan()
    {
        long personID = inputPersonID();
        String title = inputTitle();
        long lendingID = inputLendingID();
        String date = inputDate();
        String period = inputPeriod();
        
        //_loanCtr.createLoan(personID, title, lendingID, date, period);
        _loanCtr.createLoan(personID, title, lendingID, date, period);
    }
    
    public void removeLoan()
    {
        long lendingID = inputLendingID();
        
        _loanCtr.removeLoan(lendingID);
    }
    
    public void listAllLoans()
    {
        String loans = _loanCtr.listAllLoans();
        
        System.out.println("\f" + loans);
        System.out.print("Press " + "1 " + "to show menu: ");
        MainMenuUI.pause();
    }
}
